<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<c:if test="${userID==null}">
  <c:redirect url="index-msa.jsp" />
</c:if>

<c:if test="${userType!='A'}">
  <c:redirect url="main.jsp" />
</c:if>

<c:if test="${param.mode=='del'}">
  <sql:update dataSource="${dataSource}">
  delete from t_users where c_uid = ? 
  <sql:param value="${param.target}" />
  </sql:update>

  <h3>User deleted</h3>
</c:if>

<html>
  <head>
    <title>Edit Users</title>
  </head>

  <body link="#000000" vlink="#000000" alink="#000000">
    <p>The following users exist in your forum.</p>
    <sql:query var="users" dataSource="${dataSource}">
    select c_uid,c_type from t_users order by c_uid</sql:query>

    <table border="0" width="410">
      <tr>
        <td bgcolor="#0000FF" width="115">
          <b>
            <font color="#FFFFFF" size="4">Action</font>
          </b>
        </td>

        <td bgcolor="#0000FF" width="35">
          <b>
            <font color="#FFFFFF" size="4">User</font>
          </b>
        </td>

        <td bgcolor="#0000FF" width="246">
          <b>
            <font color="#FFFFFF" size="4">Type</font>
          </b>
        </td>
      </tr>

      <c:forEach var="row" items="${users.rows}"
      varStatus="status">
        <c:url value="${pageContext.request.requestURI}" var="del">
          <c:param name="mode" value="del" />

          <c:param name="target" value="${row.c_uid}" />
        </c:url>

        <c:url value="edituser.jsp" var="edit">
          <c:param name="mode" value="edit" />

          <c:param name="target" value="${row.c_uid}" />
        </c:url>

        <jsp:useBean id="status"
        type="javax.servlet.jsp.jstl.core.LoopTagStatus" />

        <c:choose>
          <c:when test="<%=status.getCount()%2==0%>">
            <c:set var="color" value="#FFFFFF" />
          </c:when>

          <c:otherwise>
            <c:set var="color" value="#FFFF66" />
          </c:otherwise>
        </c:choose>

        <tr bgcolor="<c:out value="${color}"/>">
        <td width="115">
          <a href="<c:out value="${del}"/>">[Delete]</a>

          <a href="<c:out value="${edit}"/>">[Edit]</a>
        </td>

        <td width="35">
          <b>
            <c:out value="${row.c_uid}" />
          </b>
        </td>

        <td width="246">
          <c:choose>
            <c:when test="${row.c_type=='A'}">Admin</c:when>

            <c:when test="${row.c_type=='R'}">Regular</c:when>

            <c:when test="${row.c_type=='G'}">Guest</c:when>

            <c:otherwise>
              <c:out value="${row.c_type}" />
            </c:otherwise>
          </c:choose>
        </td>
        </tr>
      </c:forEach>
    </table>

    <br />

    <a href="admin.jsp">[Exit]</a>
  </body>
</html>

